use std::fs;

use clap::{arg, Arg, ArgAction, ArgMatches, Command};

pub fn parse_cli() -> ArgMatches {
  Command::new("rust_interpreter")
    .author("timly, timly@aa.com")
    .version("0.0.1")
    .about("Interpreter for rust")
    .arg(
      Arg::new("backend")
        .short('b')
        .long("backend")
        .action(ArgAction::Set)
        .help("Backend to use for codegen")
        .required(false),
    )
    .subcommand(Command::new("compile").arg(arg!([NAME])))
    .get_matches()
}

pub fn compile(arg_matches: &ArgMatches) {
  let file_name = arg_matches
    .get_one::<String>("NAME")
    .expect("filename needed");

  println!("compiling {:?}", file_name);

  let source_code = fs::read_to_string(file_name).unwrap();
  println!("{}", source_code);
}
